﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Reflection;
using PDX.Services;

namespace PDX
{
    public class DefaultPropertyModel : IPropertyModel
    {
        public DefaultPropertyModel()
        {
            Ext = new PropertyModelAspectCollection();
            PropertyType = typeof(object);
        }

        public Func<object> Getter { get; set; }
        public Action<object> Setter { get; set; }

        public object Value
        {
            get
            {
                if (Getter == null)
                {
                    return System.Windows.Data.Binding.DoNothing;
                }
                return Getter();
            }
            set
            {
                if (Setter != null)
                {
                    Setter(value);
                }
            }
        }

        public bool IsReadonly
        {
            get { return Setter != null; }
        }

        public PropertyModelAspectCollection Ext { get; private set; }

        public string DisplayName { get; set; }

        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        public void CheckPropChanged()
        {
            // TODO should not raise if it hasn't changed?
            PropertyChanged(this, new PropertyChangedEventArgs("Value"));
        }


        public Type PropertyType { get; set; }
    }
}
